/*
 * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
 *
 * https://www.mall4j.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */
// 具体实现文章的**核心业务逻辑**（

package com.yami.shop.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.shop.bean.app.dto.ArticleDto;
import com.yami.shop.bean.model.Article;
import com.yami.shop.dao.ArticleMapper;
import com.yami.shop.service.ArticleService;
import lombok.AllArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 公告管理
 *
 * @author hzm
 * @date 2019-04-18 21:21:40
 */
@Service
@AllArgsConstructor
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements ArticleService {

    private ArticleMapper articleMapper;

    @Override
    @Cacheable(cacheNames = "articles", key = "'articles'")
    public List<Article> listArticle() {
        return articleMapper.selectList(new LambdaQueryWrapper<Article>()
                .eq(Article::getStatus, 1)
                .eq(Article::getIsTop, 1)
                .orderByDesc(Article::getPublishTime));
    }

    @Override
    @CacheEvict(cacheNames = "articles", key = "'articles'")
    public void removeArticleList() {
    }

    @Override
    public Page<ArticleDto> pageArticle(Page<ArticleDto> page) {
        return articleMapper.pageArticle(page);
    }

    @Override
    @Cacheable(cacheNames = "article", key = "#articleId")
    public Article getArticleById(Long articleId) {
        return articleMapper.selectById(articleId);
    }

    @Override
    @CacheEvict(cacheNames = "article", key = "#articleId")
    public void removeArticleById(Long articleId) {
    }


}
